<?php
$environment = 1;
?>
<div class="container" id="install-body">
    <div class="row">
        <div class="col-md-3">
            <div class="card border-primary mb-3">
                <div class="card-header">安装步骤</div>
                <div class="list-group list-group-flush">
                    <a href="#" class="list-group-item list-group-item-action ">
                        1.同意注册协议
                    </a>
                    <a href="#" class="list-group-item list-group-item-action active">
                        2.安装环境检测
                    </a>
                    <a href="#" class="list-group-item list-group-item-action ">
                        3.设置基础信息
                    </a>
                    <a href="#" class="list-group-item list-group-item-action ">
                        4.进行安装
                    </a>
                    <a href="#" class="list-group-item list-group-item-action ">
                        5.安装完成
                    </a>
                </div>
            </div>
        </div>
        <div class="col-md-9">
            <div class="card border-primary mb-3">
                <div class="card-header">环境检测</div>
                <div class="card-body">
                    <table class="table table-bordered mb-3 ">
                        <tbody>
                        <tr>
                            <th scope="col">基础检测</th>
                            <th scope="col" colspan="2">状态</th>
                        </tr>

                        <tr>
                            <td>PHP版本(>=5.1.0)
                            </th>
                            <td colspan="2">
                                <?php
                                if (PHP_VERSION < '5.1.0') {
                                    ?>
                                    <button type="button" class="btn btn-danger">警告</button>
                                    <?php
                                    $environment = 0;
                                } else {
                                    ?>
                                    <button type="button" class="btn btn-success">正常</button>
                                    <?php
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td>MYSQL(mysqli_connect)</td>
                            <td colspan="2">
                                <?php
                                if (function_exists('mysqli_connect')) {
                                    ?>
                                    <button type="button" class="btn btn-success">正常</button>
                                    <?php
                                } else {
                                    ?>
                                    <button type="button" class="btn btn-danger">警告</button>
                                    <?php
                                    $environment = 0;
                                }
                                ?>

                            </td>
                        </tr>
                        <tr>
                            <th>函数检测</th>
                            <th colspan="2">状态</th>
                        </tr>
                        <tr>
                            <td class="td-tooltip">file_put_contents
                            </td>
                            <td colspan="2">
                                <?php
                                if (!function_exists('file_put_contents')) {
                                    ?>
                                    <button type="button" class="btn btn-danger">警告</button>
                                    <?php
                                    $environment = 0;
                                } else {
                                    ?>
                                    <button type="button" class="btn btn-success">正常</button>
                                    <?php
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td>copy</td>
                            <td colspan="2">
                                <?php
                                if (!function_exists('copy')) {
                                    ?>
                                    <button type="button" class="btn btn-danger">警告</button>
                                    <?php
                                    $environment = 0;
                                } else {
                                    ?>
                                    <button type="button" class="btn btn-success">正常</button>
                                    <?php
                                }
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td>imagecreate</td>
                            <td colspan="2"><?php
                                if (!function_exists('imagecreate')) {
                                    ?>
                                    <button type="button" class="btn btn-danger">警告</button>
                                    <?php
                                    $environment = 0;
                                } else {
                                    ?>
                                    <button type="button" class="btn btn-success">正常</button>
                                    <?php
                                }
                                ?></td>
                        </tr>
                        <tr>
                            <td>session</td>
                            <td colspan="2"><?php
                                if ($_SESSION['install'] != 'RKCMS') {
                                    ?>
                                    <button type="button" class="btn btn-danger">警告</button>
                                    <?php
                                    $environment = 0;
                                } else {
                                    ?>
                                    <button type="button" class="btn btn-success">正常</button>
                                    <?php
                                }
                                ?></td>
                        </tr>
                        <tr>
                            <th>目录权限</th>
                            <th>是否存在</th>
                            <th>可写</th>
                        </tr>
                        <?php
                        $documentRoot = $_SERVER['DOCUMENT_ROOT'];
                        $folders = array(
                            '/assets',
                            '/backend/assets',
                            '/backend/protected/runtime',
                            '/common',
                            '/frontend/protected/runtime',
                        );
                        foreach ($folders as $folder) {
                            $folderPath = $documentRoot . $folder;
                            ?>
                            <tr>
                                <td><?php echo $folderPath; ?></td>
                                <td>
                                    <?php
                                    if (file_exists($folderPath)) {
                                        ?>
                                        <button type="button" class="btn btn-success">正常</button>
                                        <?php
                                    } else {
                                        ?>
                                        <button type="button" class="btn btn-danger">警告</button>
                                        <?php
                                        $environment = 0;
                                    }
                                    ?>
                                </td>
                                <td>
                                    <?php
                                    if (is_writable($folderPath)) {
                                        ?>
                                        <button type="button" class="btn btn-success">正常</button>
                                        <?php
                                    } else {
                                        ?>
                                        <button type="button" class="btn btn-danger">警告</button>
                                        <?php
                                        $environment = 0;
                                    }
                                    ?>
                                </td>
                            </tr>
                            <?php
                        }
                        ?>
                        <tr>
                            <th>文件权限</th>
                            <th>是否存在</th>
                            <th>可写</th>
                        </tr>
                        <?php
                        $files = array(
                            '/common/database.php',
                        );
                        foreach ($files as $file) {
                            $filePath = $documentRoot . $file;
                            ?>
                            <tr>
                                <td><?php echo $filePath; ?></td>
                                <td>
                                    <?php
                                    if (file_exists($filePath)) {
                                        ?>
                                        <button type="button" class="btn btn-success">正常</button>
                                        <?php
                                    } else {
                                        ?>
                                        <button type="button" class="btn btn-danger">警告</button>
                                        <?php
                                        $environment = 0;
                                    }
                                    ?>
                                </td>
                                <td>
                                    <?php
                                    if (is_writable($filePath)) {
                                        ?>
                                        <button type="button" class="btn btn-success">正常</button>
                                        <?php
                                    } else {
                                        ?>
                                        <button type="button" class="btn btn-danger">警告</button>
                                        <?php
                                        $environment = 0;
                                    }
                                    ?>
                                </td>
                            </tr>
                            <?php
                        }
                        Yii::app()->session['environment']=$environment;

                        ?>
                        </tbody>
                    </table>
                </div>
            </div>
            <form action="index.php?r=install/default/information" method="post" class="mb-3">
                <input type="hidden" name="YII_CSRF_TOKEN" value="<?php echo Yii::app()->request->csrfToken; ?>"/>
                <?php
                if(isset($this->data['message'])){
                    ?>
                    <div class="form-group">
                        <div class="alert alert-dismissible alert-warning">
                            <button type="button" class="close" data-dismiss="alert">&times;</button>
                            <p class="mb-0">
                                <?php echo $this->data['message']; ?>
                            </p>
                        </div>
                    </div>
                    <?php
                }
                ?>
                <?php
                if($environment == 1){
                    ?>
                    <div class="form-group">
                        <button type="submit" class="btn btn-primary btn-block btn-lg">下一步</button>
                    </div>
                    <?php
                }else{
                    ?>
                    <div class="form-group">
                        <button type="submit" class="btn btn-danger btn-block btn-lg disabled" disabled="disabled">请先解决警告，然后刷新页面重试</button>
                    </div>
                    <?php
                }
                ?>
            </form>
            <div class="card border-primary mb-3">
                <div class="card-header">说明</div>
                <div class="card-body">
                    <div class="list-group">
                        <a href="#" class="list-group-item list-group-item-action flex-column align-items-start ">
                            <div class="d-flex w-100 justify-content-between">
                                <h5 class="mb-1">file_put_contents</h5>
                            </div>
                            <p class="mb-1">空间如不支持file_put_contents函数，系统无法写文件。</p>
                        </a>
                        <a href="#" class="list-group-item list-group-item-action flex-column align-items-start">
                            <div class="d-flex w-100 justify-content-between">
                                <h5 class="mb-1">copy</h5>
                            </div>
                            <p class="mb-1">空间如不支持copy函数，无法上传文件。</p>
                        </a>
                        <a href="#" class="list-group-item list-group-item-action flex-column align-items-start">
                            <div class="d-flex w-100 justify-content-between">
                                <h5 class="mb-1">imagecreate</h5>
                            </div>
                            <p class="mb-1">空间如不支持imagecreate函数，无法生成验证码。</p>
                        </a>
                        <a href="#" class="list-group-item list-group-item-action flex-column align-items-start">
                            <div class="d-flex w-100 justify-content-between">
                                <h5 class="mb-1">session</h5>
                            </div>
                            <p class="mb-1">空间如不支持session，无法登陆后台。。</p>
                        </a>
                        <a href="#" class="list-group-item list-group-item-action flex-column align-items-start">
                            <div class="d-flex w-100 justify-content-between">
                                <h5 class="mb-1">linux目录不可写</h5>
                            </div>
                            <p class="mb-1">chmod 777 -R ./folder</p>
                        </a>
                        <a href="#" class="list-group-item list-group-item-action flex-column align-items-start">
                            <div class="d-flex w-100 justify-content-between">
                                <h5 class="mb-1">linux文件不可写</h5>
                            </div>
                            <p class="mb-1">chmod 777 ./filename</p>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>